package main

import (
	"fmt"
	"time"
)

/*
   Author: mahaiyuan
   Date: 2021/5/29 2:37 下午
   Description:
*/
func main() {
	ch := make(chan int, 10)
	ch2 := make(chan string, 5)
	go func() {	// 向通道ch写数据
		for i := 0; i < 20; i++ {
			time.Sleep(500 * time.Millisecond)
			ch <- i + 1
		}
		close(ch)
	}()
	go func() {	// 向通道ch2写数据
		for i := 0; i < 20; i++ {
			time.Sleep(time.Second)
			ch2 <- fmt.Sprintf("hello_%d", i)
		}
		close(ch2)
	}()
	select {
	case val := <-ch:	//读取到通道ch中的数据
		fmt.Println("data from ch is :", val)
	case val := <-ch2:	//读取到通道ch2中的数据
		fmt.Println("data from ch2 is :", val)
	}
	fmt.Println("main finish")
}